package com.huaxin.common.findutils;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;


@SuppressWarnings("all")
public class ScrollViewPager extends ViewPager {
    private static final String TAG = "ScrollViewPager";

    public ScrollViewPager(Context context) {
        super(context);
    }

    public ScrollViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    private int     mHeight;
    private boolean mIsCeiling;

    public void setHeight(int height, boolean isceiling) {
        mHeight = height;
        requestLayout();
        mIsCeiling = isceiling;
    }

    public void setHeight(int height) {
        mHeight = height;
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        if (mHeight > 0) {
            heightMeasureSpec = MeasureSpec.makeMeasureSpec(mHeight, MeasureSpec.EXACTLY);
        }
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }

    int mLastMotionY;
    int mLastMotionX;

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        int y = (int) ev.getRawY();
        int x = (int) ev.getRawX();
        switch (ev.getAction()) {
            case MotionEvent.ACTION_DOWN:
                mLastMotionY = y;
                mLastMotionX = x;
                break;
            case MotionEvent.ACTION_MOVE:
//                int deltaY = y - mLastMotionY;
//                int deleaX = x - mLastMotionX;
//
//                if (Math.abs(deleaX) > Math.abs(deltaY)) {
//                    if (!mIsCeiling) {
//                        return true;
//                    }
//
//                }
                break;
        }
        return super.dispatchTouchEvent(ev);
    }
}
